<?php
require_once 'class.database.php';
class PegawaiDao {
    public function getPegawai($nip){
        $db= Database::getInstance();
        $con=$db->getConnection(2);

        $query="SELECT nip,nama,gol,eselon,unit FROM dt_emp WHERE nip='$nip'";
        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            return $result->fetch();
        }

        return false;
    }

    public function getAllPegawai($unit){
        $db= Database::getInstance();
        $con=$db->getConnection(2);

        $query="SELECT nip,nama,gol,eselon,unit FROM dt_emp WHERE unit='$unit' and active='y'";
        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()>=1){
            return $result->fetchAll();
        }

        return false;
    }

    public function getNmPegawai($nip){
        $db= Database::getInstance();
        $con=$db->getConnection(2);

        $query="SELECT nip,nama,gol,eselon,unit FROM dt_emp WHERE nip='$nip'";
        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            $hasil=$result->fetch();
            return $hasil['nama'];
        }

        return false;
    }
}

class Pegawai {
    var $nip;
    var $nama;
    var $kd_gol;
    var $kd_unit;
    var $kd_jabatan;
}
?>
